package com.team2.cyber_eye;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.ActivityManager.MemoryInfo;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.Window;
import android.view.WindowManager;
import android.view.inputmethod.EditorInfo;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.Toast;

import com.google.ads.AdRequest;
import com.google.ads.AdSize;
import com.google.ads.AdView;
import com.team2.cyber_eye.ActivityHelpers.Util;

@SuppressLint("Registered")
public class CyberActivity extends Activity 
{
	private AdView adView;
	
	//---------------------------------------------------------------------------------------------------

	protected void CreateAdvertisement()
	{
		try
		{
			// Create an ad.
		    adView = new AdView(this, AdSize.BANNER, "a1511ac35e7d1a0");
	
		    // Add the AdView to the view hierarchy. The view will have no size
		    // until the ad is loaded.
		    LinearLayout layout = (LinearLayout) findViewById(R.id.adView);
		    layout.addView(adView);
	
		    // Create an ad request. Check logcat output for the hashed device ID to
		    // get test ads on a physical device.
		    AdRequest adRequest = new AdRequest();
		    //adRequest.addTestDevice("4F11C3F105037AC21ECA46EEFEDA9BBA");
	
		    // Start loading the ad in the background.
		    adView.loadAd(adRequest);
		}
		catch (Exception ex)
		{
			Util.LogError(ex);
		}
	}
	
	private void CreateMe(Bundle savedInstanceState)
	{
		getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
	    this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
		
	    super.onCreate(savedInstanceState);
	}
	
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		CreateMe(savedInstanceState);
	}
	
	protected void onCreate(Bundle savedInstanceState, int layout_id, String title)
	{
		CreateMe(savedInstanceState);
		
		setContentView(layout_id);
		SetTitleText(title);
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu)
	{
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.global_menu, menu);
		return true;
	}
	
	@Override
	public boolean onOptionsItemSelected(MenuItem item){
		/*switch(item.getItemId()){
		case R.id.home:
			return CheckCall(Home.class, null);
		case R.id.processedresult:
			return CheckCall(SearchByText.class, null);
		}*/
		return true;
	}

	protected void SetTitleText(String Title)
	{
		try
		{
			TitleBarView titleBar = (TitleBarView)this.findViewById(R.id.titleBar);
			if (titleBar == null)
			{
				Util.DisplayIssue(this, "Unable to set title\nFix layout");
				return;
			}
	        
			titleBar.SetTitle(Title);
		} 
		catch (Exception ex) 
		{
			Util.DisplayError(this, "Unable to set title\nFix layout", ex);
		}
	}
	
	protected boolean CheckCall(Class<?> activityClass, Bundle extras)
	{
		try
		{
			if (this.getClass() == activityClass)
				return false;
			
			Intent intent = new Intent(this, activityClass);
			if (extras != null) intent.putExtras(extras);
			startActivity(intent);
			return true;
		} catch (Exception ex) {
			Util.DisplayError(this, "Error unable to display activity: " + activityClass.getCanonicalName(), ex);
			
			return false;
		}
	}
}
